/**
 * Copyright 2008-2009 HAN.BIFANG
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 */
package han.bifang.gwt.client.stat.content.log;

import han.bifang.gwt.client.common.EntityConstants;
import han.bifang.gwt.client.common.entity.StatDetailLog;
import han.bifang.gwt.client.stat.StatMessages;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.ListBox;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
import com.google.gwt.user.client.ui.HTMLTable.ColumnFormatter;

/**
 * 
 * @Author kent
 */
public class ConditionPanel extends Composite {
	private LogMgmtContent lmc;
	private VerticalPanel panel;
	private StatMessages cons;
	private TextBox busCode, serCode,version,requestId, before, after;
	private ListBox status;
	
	public ConditionPanel(StatMessages cons1,LogMgmtContent lm){
		this.lmc = lm;
		this.cons = cons1;
		
		FlexTable table = new FlexTable();
		table.setWidth("100%");
		table.setCellPadding(1);
		table.setCellSpacing(1);
		table.setBorderWidth(1);


		
		ColumnFormatter cc = table.getColumnFormatter();
		cc.setWidth(0, "18%");
		cc.setWidth(1, "32%");
		cc.setWidth(2, "18%");
		cc.setWidth(3, "32%");
		

		FlexCellFormatter cf = table.getFlexCellFormatter();
		

		table.setHTML(0, 0, cons.busCode());
		cf.setStyleName(0, 0, "tablecol");
		
		busCode = new TextBox();
		busCode.setVisibleLength(20);
		table.setWidget(0, 1, busCode);

		table.setHTML(0, 2, cons.requestId());
		cf.setStyleName(0, 2, "tablecol");

		requestId = new TextBox();
		requestId.setVisibleLength(20);
		table.setWidget(0, 3, requestId);
		
		table.insertRow(1);
		table.setHTML(1, 0, cons.serviceCode());
		cf.setStyleName(1, 0, "tablecol");
		serCode = new TextBox();
		serCode.setVisibleLength(20);
		table.setWidget(1, 1, serCode);
		
		table.setHTML(1, 2, cons.version());
		cf.setStyleName(1, 2, "tablecol");
		version = new TextBox();
		version.setVisibleLength(20);
		table.setWidget(1, 3, version);
		
		table.insertRow(2);
		table.setHTML(2, 0, cons.before());
		cf.setStyleName(2, 0, "tablecol");
		before = new TextBox();
		before.setVisibleLength(20);
		table.setWidget(2, 1, before);
		
		table.setHTML(2, 2, cons.after());
		cf.setStyleName(2, 2, "tablecol");
		after = new TextBox();
		after.setVisibleLength(20);
		table.setWidget(2, 3, after);
		
		table.insertRow(3);
		table.setHTML(3, 0, cons.status());
		cf.setStyleName(3, 0, "tablecol");
		status = new ListBox();
		status.addItem("","");
		status.addItem(cons.success(), EntityConstants.STATUS_OK);
		status.addItem(cons.error(), EntityConstants.STATUS_ERROR);
		
		before.setVisibleLength(20);
		table.setWidget(3, 1, status);
		
		Button b = new Button(cons.search());
		b.addClickListener(new ClickListener(){

			
			public void onClick(Widget sender) {
				StatDetailLog log = new StatDetailLog();
				if(busCode.getText() != null)
					log.setBusCode(busCode.getText());
				if(serCode.getText() != null)
					log.setServiceCode(serCode.getText());
				if(version.getText() != null)
					log.setVersion(version.getText());
				if(requestId.getText() != null){
					log.setRequestId(requestId.getText());
				}
				if(status.getSelectedIndex() > 0){
					log.setStatus(status.getValue(status.getSelectedIndex()));
				}
				lmc.refresh(log, before.getText(), after.getText());
				
				
			}});
		table.setWidget(3, 2, b);
		cf.setColSpan(3, 2, 2);
		
		initWidget(table);
	}

}